package com.ai.mapper.comm;

import com.ai.model.vo.DictModel;
import com.ai.model.vo.DictModelMany;
import com.ai.entity.comm.SysDict;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author chen
 * @since 2023-03-28 16:52:35
 */
public interface SysDictMapper extends BaseMapper<SysDict> {

    @Select("select ${text} as 'text' from ${table} where ${code}= #{key}")
    String queryTableDictTextByKey(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("key") String key);


    @Select(" select s.name from sys_dict_item s \n" +
            "\t\t   where s.dict_id = (select id from sys_dict where code = #{code})\n" +
            "\t\t   and s.code = #{key}")
    String queryDictTextByKey(@Param("code") String code, @Param("key") String key);


    @Select("select s.name as 'value',s.code as 'text' from sys_dict_item s\n" +
            "\t\t   where dict_id = (select id from sys_dict where code = #{code})")
    List<DictModel> queryDictItemsByCode(@Param("code") String code);

    @Select("  select s.code as 'value',s.name as 'text' from sys_dict_item s\n" +
            "\t\t   where dict_id = (select id from sys_dict where code = #{code})")
    List<DictModel> queryEnableDictItemsByCode(@Param("code") String code);


    @Select(" select ${text} as 'text',${code} as 'value' from ${table}")
    List<DictModel> queryTableDictItemsByCode(@Param("table") String table, @Param("text") String text, @Param("code") String code);


    List<DictModelMany> queryManyDictByKeys(@Param("dictCodeList") List<String> dictCodeList, @Param("keys") List<String> keys);

    @Select("select ${text} as 'text', ${code} as 'value' from ${table} where ${code} IN (\n" +
            "        <foreach item='key' collection='keys' separator=','>\n" +
            "            #{key}\n" +
            "        </foreach>\n" +
            "        )")
    List<DictModel> queryTableDictTextByKeys(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("keys") List<String> keys);
}
